# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=hunter
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=3.6.1
pkgrel=2
pkgdesc="Hunter is a flexible code tracing toolkit (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
url='https://github.com/ionelmc/python-hunter'
license=('BSD')
depends=("${MINGW_PACKAGE_PREFIX}-python-colorama"
         "${MINGW_PACKAGE_PREFIX}-python-manhole")
optdepends=("${MINGW_PACKAGE_PREFIX}-gdb: for remote support")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-wheel"
             "${MINGW_PACKAGE_PREFIX}-python-setuptools"
             "${MINGW_PACKAGE_PREFIX}-python-setuptools-scm"
             "${MINGW_PACKAGE_PREFIX}-cython"
             "${MINGW_PACKAGE_PREFIX}-cc")
checkdepends=("${MINGW_PACKAGE_PREFIX}-python-pytest-benchmark"
              "${MINGW_PACKAGE_PREFIX}-python-pytest-runner"
              #"${MINGW_PACKAGE_PREFIX}-python-process-tests"
              #"${MINGW_PACKAGE_PREFIX}-python-virtualenv"
             )
options=('!strip')
source=("${_realname}-${pkgver}.tar.gz::https://github.com/ionelmc/python-hunter/archive/v$pkgver.tar.gz")
sha512sums=('1215da594c51cfce6341e3193de14a3386de4d28f0e0745c11b8bd6ba45d33d91628b8abfb528716968f119fa6ef64e7e2fb9ee222af16bfc8519eda354edd11')

prepare() {
  rm -rf python-build-${MSYSTEM} || true
  cp -r "python-${_realname}-${pkgver}" "python-build-${MSYSTEM}"

  export SETUPTOOLS_SCM_PRETEND_VERSION="${pkgver}"
}

build() {
  msg "Python build for ${MSYSTEM}"
  cd "${srcdir}/python-build-${MSYSTEM}"
  ${MINGW_PREFIX}/bin/python setup.py build
}

package() {
  cd "${srcdir}/python-build-${MSYSTEM}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python setup.py install --prefix=${MINGW_PREFIX} \
    --root="${pkgdir}" --optimize=1 --skip-build

  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE"

  for _f in "${pkgdir}${MINGW_PREFIX}"/bin/*-script.py; do
    # Remove shebang line
    sed -e '1 { s/^#!.*$// }' -i "${_f}"
  done
}
